var $mFlags;
var $mTrxLevel = 0;
var $mErrorCount = 0;
+ var $mLBInfo = array();
/**#@-*/
#------------------------------------------------------------------------------
return wfSetVar( $this->mErrorCount, $count );
}
+ /**
+ * Properties passed down from the server info array of the load balancer
+ */
+ function getLBInfo( $name = NULL ) {
+ if ( is_null( $name ) ) {
+ return $this->mLBInfo;
+ } else {
+ if ( array_key_exists( $name, $this->mLBInfo ) ) {
+ return $this->mLBInfo[$name];
+ } else {
+ return NULL;
+ }
+ }
+ }
+
+ function setLBInfo( $name, $value = NULL ) {
+ if ( is_null( $value ) ) {
+ $this->mLBInfo = $name;
+ } else {
+ $this->mLBInfo[$name] = $value;
+ }
+ }
+
/**#@+
* Get function
*/
* If the failFunction is set to a non-zero integer, returns success
*/
function open( $server, $user, $password, $dbName ) {
+ global $wguname;
+
# Test for missing mysql.so
# First try to load it
if (!@extension_loaded('mysql')) {
if ( $this->mConn !== false ) {
$success = @/**/mysql_select_db( $dbName, $this->mConn );
if ( !$success ) {
- wfDebug( "Error selecting database \"$dbName\": " . $this->lastError() . "\n" );
+ $error = "Error selecting database $dbName on server {$this->mServer} " .
+ "from client host {$wguname['nodename']}\n";
+ wfDebug( $error );
}
} else {
wfDebug( "DB connection error\n" );
if ( !$success ) {
$this->reportConnectionError();
}
+
+ global $wgDBmysql5;
+ if( $wgDBmysql5 ) {
+ // Tell the server we're communicating with it in UTF-8.
+ // This may engage various charset conversions.
+ $this->query( 'SET NAMES utf8' );
+ }
+
$this->mOpened = $success;
return $success;
}
/**
* @access private
- * @param string $msg error message ?
+ * @param string $error fallback error message, used if none is given by MySQL
*/
- function reportConnectionError() {
+ function reportConnectionError( $error = 'Unknown error' ) {
+ $myError = $this->lastError();
+ if ( $myError ) {
+ $error = $myError;
+ }
+
if ( $this->mFailFunction ) {
if ( !is_int( $this->mFailFunction ) ) {
$ff = $this->mFailFunction;
- $ff( $this, $this->lastError() );
+ $ff( $this, $error );
}
} else {
- wfEmergencyAbort( $this, $this->lastError() );
+ wfEmergencyAbort( $this, $error );
}
}
if ( $wgProfiling ) {
# generalizeSQL will probably cut down the query to reasonable
# logging size most of the time. The substr is really just a sanity check.
- $profName = 'query: ' . $fname . ' ' . substr( Database::generalizeSQL( $sql ), 0, 255 );
+
+ # Who's been wasting my precious column space? -- TS
+ #$profName = 'query: ' . $fname . ' ' . substr( Database::generalizeSQL( $sql ), 0, 255 );
+ $profName = 'query: ' . substr( Database::generalizeSQL( $sql ), 0, 255 );
+
wfProfileIn( 'Database::query' );
wfProfileIn( $profName );
}
# Add a comment for easy SHOW PROCESSLIST interpretation
if ( $fname ) {
- $commentedSql = "/* $fname */ $sql";
+ $commentedSql = preg_replace("/\s/", " /* $fname */ ", $sql, 1);
} else {
$commentedSql = $sql;
}
$tailOpts .= " ORDER BY {$options['ORDER BY']}";
}
if (isset($options['LIMIT'])) {
- $tailOpts .= $this->limitResult('', $options['LIMIT'],
+ $tailOpts .= $this->limitResult('', $options['LIMIT'],
isset($options['OFFSET']) ? $options['OFFSET'] : false);
}
if ( is_numeric( array_search( 'FOR UPDATE', $options ) ) ) {
$opts = array();
if ( in_array( 'LOW_PRIORITY', $options ) )
$opts[] = $this->lowPriorityOption();
- if ( in_array( 'IGNORE', $options ) )
+ if ( in_array( 'IGNORE', $options ) )
$opts[] = 'IGNORE';
return implode(' ', $opts);
}
-
+
/**
* UPDATE wrapper, takes a condition array and a SET array
*
* $mode: LIST_COMMA - comma separated, no field names
* LIST_AND - ANDed WHERE clause (without the WHERE)
* LIST_SET - comma separated with field names, like a SET clause
- * LIST_NAMES - comma separated field names
+ * LIST_NAMES - comma separated field names
*/
function makeList( $a, $mode = LIST_COMMA ) {
if ( !is_array( $a ) ) {
$s=str_replace(array('%','_'),array('\%','\_'),$s);
return $s;
}
-
+
/**
* Returns an appropriately quoted sequence value for inserting a new row.
* MySQL has autoincrement fields, so this is just NULL. But the PostgreSQL
while ( $row = $this->fetchObject( $res ) ) {
if ( $row->User == 'system user' ) {
if ( ++$slaveThreads == 2 ) {
- # This is it, return the time
- return $row->Time;
+ # This is it, return the time (except -ve)
+ if ( $row->Time > 1>>31 ) {
+ return 0;
+ } else {
+ return $row->Time;
+ }
}
}
}
function encodeBlob($b) {
return $b;
}
-
- function notNullTimestamp() {
- return "!= 0";
- }
- function isNullTimestamp() {
- return "= '0'";
- }
}
/**
/**
* @todo document
*/
- function ResultWrapper( $database, $result ) {
+ function ResultWrapper( &$database, $result ) {
$this->db =& $database;
$this->result =& $result;
}
if ( is_object( $wgMessageCache ) ) {
$wgMessageCache->disable();
}
-
- $msg = wfGetSiteNotice();
- if($msg == '') {
- $msg = str_replace( '$1', $error, $noconnect );
+
+ if ( trim( $error ) == '' ) {
+ $error = $this->mServer;
}
- $text = $msg;
+
+ wfLogDBError( "Connection error: $error\n" );
+
+ $text = str_replace( '$1', $error, $noconnect );
+ $text .= wfGetSiteNotice();
if($wgUseFileCache) {
if($wgTitle) {